Interactive Demonstration of the Difference Quotient

Created: July 2009 (David Woods)

This notebook graphically demonstrates the calculation of the difference quotient of a user defined function. The function is typed in by the user and must be done using proper Mathematica syntax. After typing in your function be sure to click "Ok" or hit the "Enter" key on the main keyboard. Do not hit the "Enter" key on the numeric keypad. The default function is Sin[x]. 

The starting "x" value (aka "a") and the value of "h"  can be chosen using the sliders or typed in at the right of each slider. Again, do not hit the "Enter" key on the numeric keypad when manually entering these values.

Only use the "Enter" key on the numeric keypad if you want to initiate changes that you have made to the notebook code itself.  If you decide to make changes to the code below,  it would be a good idea make a backup copy of the original code first.

If you do not want to display the code during a classroom demonstration you can select and copy the output panel. Then open new temporary notebook and paste the output panel into it.

The controls are fairly straightforward. Just play around with them and you should get the idea. If you have any questions feel free to contact Dave Woods at: dwoods1@austincc.edu

Main Code

Manipulate[
(* This section makes some basic definitions and calculations *)
y0=function/.x->x0;
y=function/.x->(x0+h);
derivative=(∂_x)(function);
h=h1+hfine;
If[Abs[h]>.00000001,m=(y-y0)/h,m=(derivative/.x->x0)];

(* This section creates the graphics objects *)
functlabel=Text@Style[Row[{Style["f",Italic],"(",Style["x",Italic],") = ",ToString[function,TraditionalForm],",   "}],22,Blue];
x0label=Text@Style[Row[{Style["a",Italic]," = ",ToString[x0,TraditionalForm]," ,   "}],20,Blue];
hlabel=Text@Style[Row[{Style["h",Italic]," = ",ToString[h,TraditionalForm]," ,   "}],20,Blue];
diffquot=m;
dqlabel=Text@Style[Row[{Style["((f (x + h) - f (x))/h)",Italic]," = ",ToString[diffquot,TraditionalForm]," ,   "}],20,Blue];
If[showderiv==True,deriv=Text@Style[Row[{Style["f'(x)= ",Italic],(derivative/.x->x0)}],20,Blue],deriv=Null];

point1=Graphics[{PointSize[.014],Black,Point[{x0,function/.x->x0}]}];
point2=Graphics[{PointSize[.014],Black,Point[{x0+h,function/.x->(x0+h)}]}];

fplot=Plot[function,{x,-a[[1]]+b[[1]],a[[1]]+b[[1]]},PlotRange->{-a[[2]]+b[[2]],a[[2]]+b[[2]]},PlotStyle->{Thickness[.005]},ImageSize->Full];
secline=Plot[y0+m(x1-x0),{x1,-a[[1]]+b[[1]],a[[1]]+b[[1]]},PlotRange->{-a[[2]]+b[[2]],a[[2]]+b[[2]]},PlotStyle->{Thickness[.004],Red},ImageSize->Full];
If[showtangent==True, tanline=Plot[y0+(derivative/.x->x0)*(x1-x0),{x1,-a[[1]]+b[[1]],a[[1]]+b[[1]]},PlotRange->{-a[[2]]+b[[2]],a[[2]]+b[[2]]},PlotStyle->{Thickness[.004],Green},ImageSize->600],tanline=Plot[10000,{x1,-a[[1]]+b[[1]],a[[1]]+b[[1]]},PlotRange->{-a[[2]]+b[[2]],a[[2]]+b[[2]]},PlotStyle->{Thickness[0],Black},ImageSize->Full]];

(* This command displays the graphics objects *)
Column[{Row[{functlabel,x0label,hlabel,dqlabel,deriv}],Show[fplot,secline,tanline,point1,point2]
}],

(* This section creates and formats the input/output controls in the panel*)
{function,Sin[x]},
{{x0,0,"a value"},-10,10,ControlType->Slider,ImageSize->700,Appearance->{"Labeled"}},
{{h1,1,"h value"},-10,10,ControlType->Slider,ImageSize->700,Appearance->{"Labeled"}},
{{hfine,0,"h fine tune"},-.1,.1,ImageSize->Medium,BaselinePosition->Right},
{{showtangent,True,"Show Tangent"},{True,False},ControlPlacement->Left},
{{showderiv,True,"Show f'(x)"},{True,False},ControlPlacement->Left},
{{a,{3,3},"Scale"},{1/2,1/2},{10,10},ControlPlacement->Left},{{b,{0,0},"Shift"},{-10,-10},{10,10},ControlPlacement->Left},
 ControlPlacement->Center]